package parser

import (
	"org/leazen/golearning/crawler/engine"
	"regexp"
)

const cityListRe = `<a href="(http://city.zhenai.com/[0-9a-z]+)"[^>]*>([^<]+)</a>`

func ParseCityList(contents []byte) engine.ParseResult {

	re := regexp.MustCompile(cityListRe)
	macthes := re.FindAllSubmatch(contents, -1)

	result := engine.ParseResult{}
	var number  = 10
	for _, m := range macthes {
		result.Items = append(result.Items,"city  "+ string(m[2]))
		result.Requests = append(result.Requests, engine.Request{
			Url:       string(m[1]),
			ParseFunc: ParseCity,
		})

		number--

		if number == 0 {
			break
		}
	}

	return result
}
